﻿using System;
using Jink.Playground.Domain;
using System.Linq;
using XenoGears.Assertions;

namespace Jink.Playground.MockData
{
    internal static class Convert
    {
        public static SPList ToDomainObject(this PdpList pdpList)
        {
            var spList = new SPList{Name = "pdp"};
            spList.Items = pdpList.Items.Select(item => new SPListItem(spList, item)).ToList();
            return spList;
        }

        public static PdpList ToDatabaseObject(this SPList spList)
        {
            (spList.Name == "pdp").AssertTrue();
            return new PdpList{Items = spList.Items.Select(item => new PdpListItem
            {
                Id = (int)item.Fields["Id"],
                User = (SPUser)item.Fields["User"],
                Goal = (String)item.Fields["Goal"],
                Deadline = (DateTime)item.Fields["Deadline"],
                Progress = (double)item.Fields["Progress"],
            }).ToList()};
        }
    }
}
